#ifndef __DEF_IMPORTDIALOG_H__
#define __DEF_IMPORTDIALOG_H__

#include <wx/wx.h>
#include <wx/datectrl.h>
#include <wx/textfile.h>
#include <wx/xml/xml.h>
#include "appconstant.h"
#include "dbkakeibo.h"

class ImportDialog: public wxDialog
{
public:
	ImportDialog(wxWindow *parent);
	~ImportDialog(void) {};
	void Clear(void);
protected:
	wxRadioBox *im_ImportType;
	wxChoice *im_ImportFormat;
	wxChoice *im_ImportDelimiter;
	wxCheckListBox *im_ImportDBList;
	wxTextCtrl *im_ImpotFilePath;
	wxButton *im_FileRefBtn;
	wxCheckBox *im_ImportUseRange;
	wxDatePickerCtrl *im_ImportRangeBegin;
	wxDatePickerCtrl *im_ImportRangeEnd;
	wxStaticBox *im_ImportOptionArea;
		wxCheckBox *im_ImOptReplace;
		wxCheckBox *im_ImOptAddExpense;
	wxButton *im_ExecuteBtn;
	wxTextCtrl *im_ExecLog;
	
	wxButton *im_CloseBtn;
	wxLogTextCtrl *im_ExecLogArea;

	void im_CloseBtn_clicked(wxCommandEvent &event);
	void im_ImportType_selected(wxCommandEvent &event);
	void im_ImportUseRange_selected(wxCommandEvent &event);
	void im_FileRefBtn_clicked(wxCommandEvent &event);
	void im_ExecuteBtn_clicked(wxCommandEvent &event);
	void im_ImportFormat_changed(wxCommandEvent &event);

private:
	DECLARE_EVENT_TABLE()
	void ExportData(const wxString &filepath);
	wxString TableDataFunction(wxTextFile &tfile, int target);
	wxString generate_ExportFormat(const wxString &table, wxSQLite3ResultSet &rset);

	void ImportData(const wxString &filepath);
	bool ImportDataFunction(wxXmlNode *tfile);
	wxString parse_ImportFormat(const wxString &table, wxArrayString &name, wxArrayString &arr);

	int totalcnt;
	int successcnt;
	int failcnt;
};

enum {
	import_close = 300,
	import_execute,
	import_type,
	import_fileref,
	import_userange,
	import_format
};

#endif